package com.haizhi.script;

import com.haizhi.enums.Province;
import com.haizhi.gsxt.ProvinceTable;
import com.haizhi.mongo.MongoHandler;
import com.haizhi.util.PropertyUtil;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.bson.Document;

public class CountAllClueTable {

    private static final Logger logger = LogManager.getLogger(CountAllClueTable.class);


    static {
        PropertyUtil.loadProperties("mongo.properties");
    }

    public static void main(String... args) {
        MongoHandler mongoHandler = new MongoHandler(PropertyUtil.getProperty("mongo.host"),
                PropertyUtil.getProperty("mongo.username"),
                PropertyUtil.getProperty("mongo.password"),
                PropertyUtil.getProperty("mongo.auth.db"));
        MongoDatabase mongoDatabase = mongoHandler.getDb(PropertyUtil.getProperty("mongo.database"));
        for (Province province : Province.values()) {
            String table = ProvinceTable.getProvinceTable(province.getValue());
            MongoCollection<Document> collection = mongoDatabase.getCollection(table);
            logger.info("当前省份: province = {} 总量: {}", province.getValue(), collection.count());
        }
    }
}
